"""
声音管理器类
用于管理voice_id及其描述信息
"""

import json
from typing import Dict, Optional


class VoiceManager:
    """
    声音管理器类，用于维护voice_id和声音描述的映射关系
    """
    
    def __init__(self):
        """
        初始化声音管理器
        """
        # 默认声音配置
        self.voices = {
            "pqHfZKP75CvOlQylNhV4": {
                "name": "中年男声",
                "description": "26岁欧洲男人的声音",
                "gender": "male",
                "language": "多语言"
            },
            "Xb7hH8MSUJpSbSDYk0k2": {
                "name": "中年女声",
                "description": "26岁非洲女人的声音",
                "gender": "female",
                "language": "多语言"
            },
            "N2lVS1w4EtoT3dr4eOWO": {
                "name": "低沉男声",
                "description": "50岁欧洲男人的声音",
                "gender": "male",
                "language": "多语言"
            }
        }
    
    def get_voice(self, voice_id: str) -> Optional[Dict[str, str]]:
        """
        根据voice_id获取声音信息
        
        Args:
            voice_id (str): 声音ID
            
        Returns:
            Optional[Dict[str, str]]: 声音信息，如果不存在则返回None
        """
        return self.voices.get(voice_id)
    
    def get_voice_name(self, voice_id: str) -> str:
        """
        根据voice_id获取声音名称
        
        Args:
            voice_id (str): 声音ID
            
        Returns:
            str: 声音名称，如果不存在则返回"未知声音"
        """
        voice = self.voices.get(voice_id)
        if voice:
            return voice.get("name", "未知名称")
        return "未知声音"
    
    def get_voice_description(self, voice_id: str) -> str:
        """
        根据voice_id获取声音描述
        
        Args:
            voice_id (str): 声音ID
            
        Returns:
            str: 声音描述，如果不存在则返回"无描述"
        """
        voice = self.voices.get(voice_id)
        if voice:
            return voice.get("description", "无描述")
        return "无描述"
    
    def list_voices(self) -> Dict[str, Dict[str, str]]:
        """
        获取所有声音信息
        
        Returns:
            Dict[str, Dict[str, str]]: 所有声音信息
        """
        return self.voices.copy()
    
# 创建全局声音管理器实例
voice_manager = VoiceManager()